-- Leviathan (c) v.v.balashoff
local Class = require('leviathan/Class')

local TimerSystem = Class:derive('UITimerSystem')

function TimerSystem:new(domain)
    self.name = 'TimerSystem'
    self.domain = domain
end

function TimerSystem:update(dt)
    local comps = self.domain.components['Timer']
    if not comps then
        return
    end
    for _, c in pairs(comps) do
        if c.enabled then
            if not c.startTime then
                c.startTime = love.timer.getTime()
            end
            if ((love.timer.getTime() - c.startTime) >= c.triggerTime) then
                c.target[c.field] = c.value
                c.enabled = false
            end
        end
    end
end

return TimerSystem
